// 导入导航
import { Navigate,useLocation} from "react-router-dom";
function Private(props) {
  const location = useLocation();
  console.log(location)
  if(sessionStorage.getItem("token")){
    // 如果token就返回Private的子组件
    return <>{props.children}</>
  }else{
    // 没有就跳转登录
    // 添加查询参数 redirect值为当前页面的pathname
    return <Navigate to={{pathname:"/",search:"?redirect="+location.pathname}} />
  }
}

export default Private;